package tsif.tcluster.service.proxy;

import tsif.tcluster.ITClusterAccessor;
import tsif.tcluster.TClusterContext;
import tsif.tcluster.service.ITClusterService;
import tsif.tcluster.session.TClusterSession;

/** 集群云服务代理 **/
public abstract class TClusterServiceProxy {
	protected long serviceId; // 服务Id
	protected String uniqueName; // 集群唯一名称(如果不是集群服务, 没有)
	protected ITClusterService service; // 服务接口

	/** 初始化服务 **/
	protected abstract boolean init(TClusterContext context, long serviceId, String uniqueName, Class<?> classValue, Object... args) throws Exception;

	/** 销毁服务 **/
	protected abstract void destroy() throws Exception;

	/** 更新 **/
	protected abstract void update();

	/** 获取集群环境 **/
	public abstract TClusterContext getContext();

	/** 获取集群访问器 **/
	public abstract ITClusterAccessor getAccessor();

	/** 接收消息 **/
	public abstract void recv(TClusterSession session, long serviceId, short code, Object data) throws Exception;

	/** 提交任务 **/
	public abstract void execute(Runnable runnable);

	public long getServiceId() {
		return serviceId;
	}

	/** 唯一服务名(非唯一服务为null) **/
	public String getUniqueName() {
		return uniqueName;
	}

	/** 获取接口 **/
	@SuppressWarnings("unchecked")
	public <T> T getService() {
		return (T) service;
	}

}
